package net.shambolica.ember.jinterface.wrappers.objects.patterns;

import com.ericsson.otp.erlang.OtpErlangObject;
import net.shambolica.ember.jinterface.wrappers.objects.EOPattern;

import java.util.Map;

/**
 * The NOT predicate pattern.
 */
public class EOPNot extends EOPattern {

    private final EOPattern pred;

    public EOPNot(EOPattern pred) {
        if (pred == null) {
            throw new IllegalArgumentException("parameter null in not predicate");
        }
        this.pred = pred;
    }

    @Override
    public Map<String, OtpErlangObject> match(OtpErlangObject term, Map<String, OtpErlangObject> acc) {
        Map<String,OtpErlangObject> origAcc = mkAcc(acc);
        return pred.match(term, mkAcc(acc)) == null ? origAcc : null;
    }

    @Override
    public boolean isAbstract() {
        return true;
    }

}
